if CLIENT then
  
surface.CreateFont( "coolvetica", 30, 500, true, false, "HealthFont" )
surface.CreateFont( "coolvetica", 22, 500, true, false, "HealthNumberFont" )

function HealthBar()  
	local tr = utilx.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetCursorAimVector() )
      
	-- Get a trace, Immediatly stop if it is the world, or not an NPC!
	local trace = util.TraceLine( tr )
    if (!trace.Hit) then return end
    if (!trace.HitNonWorld) then return end
	if (!trace.Entity:IsNPC()) then return end
	
	local length = LocalPlayer():GetNWInt("LookingHealth") / LocalPlayer():GetNWInt("LookingMaxHealth") * 150
      
	local x = ScrW() / 2
	local y = ScrH() - 17
	  
    if LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") >= LocalPlayer():GetNWInt("LookingHealth") then
        surface.SetDrawColor( 255,0,0,255 )
        surface.DrawRect( x - 75, y, 150, 15 )
        surface.SetDrawColor( 0,255,0,255 )
        surface.DrawRect( x - 75, y, length, 15 )
        draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x, y + 9, Color(120,120,120,255),1,1) 
    elseif LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") <= LocalPlayer():GetNWInt("LookingHealth") then
        surface.SetDrawColor( 255,0,0,255 )
        surface.DrawRect( x - 75, y, 150, 15 )
        surface.SetDrawColor( 0,255,0,255 )
        surface.DrawRect( x - 75, y, 150, 15 )
        draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x, y + 9, Color(120,120,120,255),1,1) 
    end
	  
end
hook.Add("HUDPaint", "bleh", HealthBar)
  
else

  AddCSLuaFile("healthbar.lua")
  function HealthBarGetHealth()  
   for k, v in pairs(player.GetAll()) do
      local tr = utilx.GetPlayerTrace( v, v:GetCursorAimVector() )
      local trace = util.TraceLine( tr )
      if (!trace.Hit) then return end
      if (!trace.HitNonWorld) then return end
      v:SetNWInt("LookingHealth",trace.Entity:Health())
      v:SetNWInt("LookingMaxHealth",trace.Entity:GetMaxHealth())
      if GetConVarNumber("sv_showhealthbar") == 0 then
      v:SetNWInt("HealthBarDisable",1)
      else
      v:SetNWInt("HealthBarDisable",0)
      end
   end 
  end
  hook.Add("Think", "NpcHudGetHealth", HealthBarGetHealth)
  CreateConVar("sv_showhealthbar", 1)
end
